package com.minimoment.model.service.impl;

import com.minimoment.base.BaseSupportImpl;
import com.minimoment.model.domain.User;
import com.minimoment.model.service.UserService;
import org.hibernate.Session;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 查询的时候字符串要加引号
 * from后面跟的是类名
 * Created by etund on 2014/10/30.
 */
@Service
@Transactional
public class UserServiceImpl extends BaseSupportImpl<User> implements UserService{
//    登录信息查询
    public List<User>  getByCondition(User user){
        String sql = "from User u where 1=1";
        if (user.getId()!=null)
            sql += " and u.id ="+user.getId();
        if (user.getLoginName()!=null)
            sql += " and u.loginName = '"+user.getLoginName()+"'";
        if(user.getEmail()!=null)
            sql += " and u.email = '"+ user.getEmail()+"'";
        if(user.getPassword()!=null)
            sql += " and u.password = '"+ user.getPassword()+"'";
        if(user.getGender()!=null)
            sql += " and u.gender = '"+ user.getGender()+"'";
        System.out.println(sql+"=========这是sql语句==========");
        return getSession().createQuery(sql).list();
    }
//    注册信息查询
    public List<User> registerCheck(User user){
        String sql = "from User u where 1=1";
        if (user.getId()!=null)
            sql += " and u.id ="+user.getId();
        if (user.getLoginName()!=null)
            sql += " and u.loginName = '"+user.getLoginName()+"'";
        if(user.getEmail()!=null)
            sql += " and u.email = '"+ user.getEmail()+"'";
        System.out.println(sql+"=========这是sql语句==========");
        return getSession().createQuery(sql).list();
    }
}
